import React, {useEffect} from 'react'
import {Select} from 'antd'
import {useSelector, useDispatch} from 'react-redux'
import {handleArticleCates} from '@/store2/actions'
const {Option} = Select
export default props => {
  const {onChange,value, cates} = props
  const dispatch = useDispatch()
  const articleCates = cates || useSelector(store => store.article.articleCates)
  // console.log(articleCates);

  cates || useEffect(() => {
    dispatch(handleArticleCates())
    return undefined
  }, [])

  return (
    <Select 
      defaultValue="请选择" 
      id="article-cate"
      style={{ width: '70%' }} 
      allowClear
      value={value}
      onChange={value => onChange && onChange(value, 'cate')}
    >
      {
        articleCates.length && articleCates.map(item => (
          <Option value={item.cate} key={item._id}>
            {item.cate_zh}
          </Option>
        ))
      }
    </Select>
  )
}